home *** CD-ROM | disk | FTP | other *** search
/ Acorn Risc Technologies StrongARM CD-ROM / Acorn Risc Technologies StrongARM CD-ROM.iso / ftp / documents / appnotes / 231_245 / 240c / Text
Encoding:
Text File  |  1993-11-12  |  13.4 KB  |  296 lines

  1. -----------------------------------------------------------------------------
  2. 8th October 1993 - The RISC OS Selection Model and Clipboard
  3. -----------------------------------------------------------------------------
  4. Support Group Application Note  
  5. Number:  240 
  6. Issue:   1.00 
  7. Author:  James Bye/ SH
  8. -----------------------------------------------------------------------------
  9.  
  10. Developer's Notes: 
  11.  
  12.  The second edition of the RISC OS Style Guide recommends the use of
  13. clipboard-based (cut-copy-paste) data transfer.  This application note
  14. describes how this could be implement, and how to make sure that your
  15. applications co-operate with others to promote consistent data transfer
  16. facilities.
  17.  
  18. This application note is based on a protocol designed by Iota Software Ltd.
  19.  
  20. -----------------------------------------------------------------------------
  21. Applicable Hardware:  All Acorn RISC OS based computers
  22.  
  23. Related Application Notes: The RISC OS Drag-and-Drop System
  24.  
  25.  
  26. -----------------------------------------------------------------------------
  27. Copyright (C) Acorn Computers Limited 1992
  28.  
  29. Every effort has been made to ensure that the information in this leaflet is 
  30. true and correct at the time of printing. However, the products described in
  31. this leaflet are subject to continuous development and improvements and
  32. Acorn Computers Limited reserves the right to change its specifications at
  33. any time. Acorn Computers Limited cannot accept liability for any loss or
  34. damage arising from the use of any information or particulars in this
  35. leaflet. ACORN, ECONET and ARCHIMEDES are trademarks of Acorn Computers
  36. Limited.
  37. -----------------------------------------------------------------------------
  38. Support Group
  39. Acorn Computers Limited
  40. Acorn House
  41. Vision Park
  42. Histon
  43. Cambridge
  44. CB4 4AE                                                  
  45. -----------------------------------------------------------------------------
  46.  
  47. Definitions
  48.  
  49.  Selection: The portion of a document which the user has chosen as the
  50. target for subsequent operations.  This may be a contiguous selection (as in
  51. the case of selected text) or a non-contiguous selection (as in the case of
  52. a number of selected files in the Filer).
  53.  
  54.  Caret: the position in a document where typed characters or pasted
  55. clipboard contents will be placed.  In textual documents, the caret is often
  56. shown by an I-beam,  but other representations of the caret may be more
  57. appropriate for other kinds of data.  Some editors, such as !Draw, do not
  58. have a visible insertion point, but still "grab the caret" in order to
  59. receive keystroke events.
  60.  
  61. Input focus: the window where keystroke events will be delivered.
  62.  
  63.  Clipboard: a temporary storage area that holds data while the user is
  64. copying or moving it (either within one application or between
  65. applications).
  66.  
  67.  Cut: the operation that the user invokes to transfer the current selection
  68. to the clipboard.  The selection is deleted from the source document.
  69.  
  70. Copy: as cut, but does not delete the original.
  71.  
  72.  Paste: the operation that the user invokes to transfer the clipboard
  73. contents into a document.
  74.  
  75.  
  76. The Selection Model
  77.  
  78.  There should normally be one caret or selection active in each window. 
  79. They are mutually exclusive; a window's caret and selection are not normally
  80. visible at the same time.  When the user clicks to position the caret or
  81. makes a selection, any existing selection in the same window should be
  82. de-selected.  In text editors it is helpful to think of the caret as a
  83. zero-width selection; if the user makes a selection, then the caret becomes
  84. invisible, and if the user clicks to set the caret. then any selection is
  85. de-selected.
  86.  
  87.  Each window has its own selection, even multiple views of the same
  88. document.  Making a selection in one window should not affect any selections
  89. active in other windows.
  90.  
  91.  
  92. The Clipboard
  93.  
  94.  Copying and moving data within and between windows is accomplished by means
  95. of a temporary holding area known as the clipboard.  The clipboard supports
  96. three operations.  The Copy operation copies the selected data from the
  97. source window to the clipboard, leaving the selection intact.  The Cut
  98. operation is similar to Copy, but deletes the selected data from the
  99. document.  The Paste operation inserts a copy of the clipboard contents to
  100. the caret position of the destination window (or, if there is a selection
  101. rather than a caret, it replaces the selection with the contents of the
  102. clipboard).  The user combines these operations as required to effect the
  103. copying and movement of data.  The clipboard is a systemwide entity, so the
  104. operations work between applications as well as within one application.
  105.  
  106.  From an implementation point of view, the clipboard is not a specific area
  107. of memory, but a notional entity which applications claim and keep track of
  108. by means of messages.  The data "on" the clipboard is held by the
  109. application that performed the last "cut" or "copy" operation.
  110.  
  111.  Data entered from the keyboard, or pasted in from the clipboard, should
  112. replace the current selection if there is one, or be inserted at the caret
  113. position if there is no selection.  Graphical applications that do not have
  114. a visible caret must choose where to position pasted data in an appropriate
  115. way.  In any case, the pasted data should be automatically selected so that
  116. the user can immediately cut it again should this be desired.
  117.  
  118.  If the user replaces a selection by typing new data, the selection should
  119. be replaced by a caret and the deleted data should be cut to the clipboard
  120. as a safety measure - the user can paste it back again if the operation was
  121. unintended.  Do not do this if the selection is replaced by pasting from the
  122. clipboard, because it would prevent the same data being pasted multiple
  123. times.
  124.  
  125.  
  126. Caret / Selection / Clipboard control
  127.  
  128. Ownership of the caret / selection / clipboard
  129.  
  130.  Each task keeps a separate record of the position of the caret/selection
  131. for each of its windows.  It also stores flags to indicate whether it
  132. currently "owns" the input focus and the clipboard.
  133.  
  134.  To enable applications to track changes in the status these entities, the
  135. following message is used:
  136.  
  137.         Message_ClaimEntity (15)
  138.                 0       message size (24)
  139.                 4       task handle of task making the claim
  140.                 8       message id
  141.                 12      your_ref (0)
  142.                 16      Message_ClaimEntity
  143.                 20      flags:
  144.                             bits 0 and 1 set => caret or selection being claimed
  145.                             bit 2 set => clipboard being claimed
  146.                            all other bits reserved (must be 0)
  147.  
  148.  This message should be broadcast to all tasks as the caret / selection or
  149. clipboard are claimed.
  150.  
  151.  When the user positions the caret or makes a selection, the application
  152. should claim ownership of the input focus by broadcasting this message with
  153. bits 0 and 1 set.  When positioning the caret, the application can choose
  154. whether to use the Wimp's caret or draw its own representation of the caret
  155. more appropriate to the type of data being edited.  When making a selection,
  156. the application must hide the caret; it should do this by setting the Wimp's
  157. caret to the window containing the selection, but invisible.  This is
  158. necessary to direct keystroke events to this window.
  159.  
  160.  When a task receives this message with bits 0 or 1 set, it should check to
  161. see if any of its windows currently own  the input focus.  If  so, it should
  162. update its flag to indicate that it no longer has the focus, and remove any
  163. representation of the caret which it has drawn (unless it uses the Wimp
  164. caret, which will be undrawn automatically.)  It may optionally alter the
  165. appearance of its window to emphasize the fact that it does not have the
  166. input focus, for example by shading the selection.  A task that receives
  167. Message_ClaimEntity with only one of bits 0 and 1 set should act as if both
  168. bits were set.
  169.  
  170.  When the user performs a Cut or Copy operation. the application should
  171. claim ownership of the clipboard by broadcasting this message with bit 2
  172. set.
  173.  
  174.  When a task receives this message with bit 2 set it should set a flag to
  175. indicate that the clipboard is held by another application and deallocate
  176. the memory being used to store the clipboard contents.
  177.  
  178.  
  179. To improve performance, the following optimisation should be made:
  180.  
  181.  When claiming the input focus or clipboard, a task should check to see if
  182. it already owns that entity, and if so, there is no need to issue the
  183. broadcast.  It should then take care of updating the caret / selection /
  184. clipboard to the new value (updating the display in the case of the
  185. selection).
  186.  
  187.  
  188. LoseCaret / GainCaret events
  189.  
  190.  As far as keeping track of whether they have the input focus is concerned,
  191. applications implementing the above protocols should ignore
  192. LoseCaret/GainCaret messages   This is because the Wimp often ‘borrows’ the
  193. caret to put it in writable menu icons and when this happens the application
  194. should not regard the input focus as being lost.
  195.  
  196.  Older applications which claim the caret without using the claiming
  197. mechanism described will also not indulge in the cut/copy/paste protocol so,
  198. again, the LoseCaret event should be ignored.
  199.  
  200.  
  201. Selection History
  202.  
  203.  To return to a window that does not currently have the input focus, the
  204. user clicks in it to set the caret.  Because the caret and selection are
  205. mutually exclusive within each window, this causes any selection that was
  206. pending to be lost.  However, the user may occasionally want to return the
  207. input focus to a window without losing its selection, particularly if
  208. re-making the selection would be fiddly or time-consuming.
  209.  
  210.  Therefore a click within the current selection or in a "dead" area of the
  211. window (e.g. in a border) should be treated specially.  It should cause the
  212. window to regain the input focus without setting the caret position and
  213. hence without losing the current selection.  The application should
  214. broadcast Message_ClaimEntity with bits 0 and 1 set, and set the Wimp caret
  215. to the window.  If there is a selection in the window then the caret should
  216. be made invisible.  If there is no selection then the caret should be shown
  217. and restored to its previous position within the window.
  218.  
  219.  
  220. Cutting and pasting data
  221.  
  222.  Applications should provide menu entries for Cut, Copy and Paste
  223. operations.  Refer to the Style Guide for details of where to place these in
  224. your menu tree and which keyboard shortcuts to assign to them.
  225.  
  226. Cut
  227.  
  228.  If the application does not have a selection, then this is a not possible
  229. and should be shaded on the menu.
  230.  
  231.  If the application already owns the clipboard, it should free its current
  232. contents.  If not, it should claim the clipboard by broadcasting
  233. Message_ClaimEntity setting flags bit 2.  It should then set up its internal
  234. representation of the clipboard contents to be a copy of the selected data,
  235. and delete the selection. 
  236.  
  237. Copy
  238.  
  239. As Cut, but the selection should not be deleted.
  240.  
  241. Paste
  242.  
  243.  The application should first check to see if it owns the clipboard, and use
  244. the data directly if so.  If is does not own it, it should broadcast the
  245. following message:
  246.  
  247.         Message_DataRequest (16)
  248.                 0       message size
  249.                 4       task handle of task requesting data
  250.                 8       message id
  251.                 12      your_ref (0)
  252.                 16      Message_DataRequest
  253.                 20      window handle
  254.                 24      internal handle to indicate destination of data
  255.                 28      x
  256.                 32      y
  257.                 36      flags:
  258.                                 bit 2 set => send data from clipboard (must be 1)
  259.                                 all other bits reserved (must be 0)
  260.                 40      list of filetypes in order of preference,
  261.                           terminated by -1
  262.  
  263.  The sender must set flags bit 2, and the receiver must check this bit, and
  264. ignore the message if it is not set.  All other flags bits must be cleared
  265. by the sender and ignored by the receiver.
  266.  
  267.  If an application receiving this message owns the clipboard, it should
  268. choose the earliest filetype in the list that it can provide, and if none
  269. are possible it should provide the data its original (native) format.  Note
  270. that the list can be null, to indicate that the native data should be sent. 
  271. It should reply using the normal Message_DataSave protocol.  Bytes 20
  272. through 35 of the DataSave block should be copied directly from the
  273. corresponding bytes of the Message_DataRequest block, whilst the estimated
  274. size field, filetype and filename must be filled in.
  275.  
  276.  When the application that initiated the Paste receives the
  277. Message_DataSave, it should check the filetype to ensure that it knows how
  278. to deal with it - it may be the clipboard owner's native format.  If it
  279. cannot, it may back out of the transaction by ignoring the message. 
  280. Otherwise, it should continue with the DataSave protocol as detailed in the
  281. Programmer's Reference Manual.
  282.  
  283.  If your application needs to find out whether there is data available to
  284. paste, but does not actually want to receive the data, you should broadcast
  285. a Message_DataRequest as described above.  If no task replies (i.e. you get
  286. the message back) then there is no clipboard data available.   If a
  287. Message_DataSave is received, then you should ignore it (fail to reply),
  288. which will cause the operation to be silently aborted by the other task. 
  289. You can then use the filetype field of the Message_DataSave to determine
  290. whether the data being offered by the other task is in a suitable format for
  291. you to receive.
  292.  
  293.  This mechanism can be used if you want to shade out the Paste menu item
  294. when there is no suitable data for pasting.
  295.  
  296.